package com.im.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.im.app.mapper.WelcomeMapper;
import com.im.app.model.Welcome;
import com.im.app.service.WelcomeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 欢迎语(Welcome)表服务实现类
 *
 * @author makejava
 * @since 2023-03-20 14:21:46
 */
@Service
@Transactional(rollbackFor = Exception.class)
@Slf4j
public class WelcomeServiceImpl implements WelcomeService {

    @Resource
    private WelcomeMapper welcomeMapper;
    @Override
    public List<Welcome> queryWelcomeList(String userId) {
        QueryWrapper<Welcome> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        queryWrapper.orderByAsc("sort");
        return welcomeMapper.selectList(queryWrapper);
    }

    @Override
    public Welcome findWelcome(Integer id) {
        return welcomeMapper.selectById(id);
    }

    @Override
    public int deleteWelcome(Integer id) {
        return welcomeMapper.deleteById(id);
    }

    @Override
    public int addWelcome(Welcome welcome) {
        return welcomeMapper.insert(welcome);
    }

    @Override
    public int updateWelcome(Welcome welcome) {
        return welcomeMapper.updateById(welcome);
    }

    @Override
    public int inserts(List<Welcome> welcomes){
        return welcomeMapper.inserts(welcomes);
    }

    public int deleteByUserId(String userId){
        return welcomeMapper.deleteByUserId(userId);
    };


}

